<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of about-us
 *
 * @author QUYET
 */
class news extends Frontend_Controller {
//put your code here
    public function __construct() {
        parent::__construct();
        $this->load->model('news_m');
        $this->session->set_userdata('current_url', current_url());
    }
    
    function index(){
        $layout = 'frontend_layout/frontend';
        $view_data = array();
        if(empty($this->cart))$this->load->library('cart');
        $view_data['cart_total'] = $this->cart->total_items();
        $view_data['categories']    = modules::run('ticket/list_ticket_categories');
        $view_data['tags']    = modules::run('ticket/list_ticket_tags');
        
        $this->load->library('pagination');
        
        $per_page = 10;
        $config['full_tag_open'] = "<div class='page'>";
        $config['full_tag_close'] = '</div>';
        $config['cur_tag_open'] = '<span> ';
        $config['cur_tag_close'] = ' </span>';
        $config['next_link'] = __('admin_next');
        $config['prev_link'] = __('admin_previous');
        $config['first_link'] = __('admin_first');
        $config['last_link'] = __('admin_last');
        $config['base_url'] = base_url() . 'news/';
        $config['per_page'] = $per_page;
        $config['uri_segment'] = 2;
        $config['total_rows'] = $this->news_m->count_all_news();
        
        if(empty($config['total_rows'])) redirect('/');
        
        $off_set = $this->uri->segment(2) != '' ? $this->uri->segment(2) : 0;
        if ($off_set > 0 && $off_set == $config['total_rows']) {
            $off_set = $off_set - $per_page;
        }
        $view_data['news_infos'] = $this->news_m->get_allnews($per_page, $off_set);
        $this->pagination->initialize($config);
        $view_data['pagination'] = $this->pagination->create_links();
        $view_data['off_set'] = $off_set;
        
        if(empty($view_data['news_infos'])) redirect('/');
        $view_data['main_content'] = $this->load->view('news',$view_data,true);//modules::run('about_us');
        
        $view_data['title'] = __('admin_news');
        $view_data['keywords'] = DEFAULT_KEYWORDS;
        $view_data['description']= DEFAULT_DESCRIPTION;
        /*$view_data['title'] = $about_info->meta_title;
        $view_data['keywords'] = $about_info->meta_keyword;
        $view_data['description']= $about_info->meta_description;*/
        $view_data['slideshows_header'] = $this->ticket_model->get_top10ticket_bestseller();//get10TicketBestSeller;
        $this->load->view($layout, $view_data, FALSE);
        
    }
    
    function detail($id){
        
        if(empty($id) || !is_numeric($id)) redirect('/');
        $one_news = $this->news_m->get_onenews($id);
        
        if(empty($one_news)) redirect('/');
        $layout = 'frontend_layout/frontend';
        $view_data = array();
        if(empty($this->cart))$this->load->library('cart');
        $view_data['cart_total'] = $this->cart->total_items();
        $view_data['categories']    = modules::run('ticket/list_ticket_categories');
        $view_data['tags']    = modules::run('ticket/list_ticket_tags');        
        
        $view_data['main_content'] = $this->load->view('details',array('one_news'=>$one_news),true);//modules::run('about_us');
        
        $view_data['title'] = $one_news->meta_title;
        $view_data['keywords'] = $one_news->meta_keyword;
        $view_data['description']= $one_news->meta_description;
        
        $view_data['slideshows_header'] = $this->ticket_model->get_top10ticket_bestseller();//get10TicketBestSeller;
        $this->load->view($layout, $view_data, FALSE);
    }
}
?>
